//===============================================================================
// Microsoft patterns & practices
// Web Client Software Factory
//===============================================================================
// Copyright � Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================

using System;
using System.Collections.Generic;

namespace MVPComposibility.ContactManager.DomainModel
{
	/// <summary>
	/// Class that manages data about a single contact in
	/// the contact manegement system.
	/// </summary>
	public class Contact : ICloneable
	{
		private int _id;
		private string _name;
		private List<Address> _addresses;

		public Contact() : this(null)
		{
		}

		public Contact(string name)
		{
			_id = NewContactId;
			_name = name;
			_addresses = new List<Address>();
		}

		public const int NewContactId = -1;

		public int Id
		{
			get { return _id; }
			set { _id = value; }
		}

		public string Name
		{
			get { return _name; }
			set { _name = value; }
		}

		public IList<Address> Addresses
		{
			get { return _addresses.ToArray(); }
		}

		public void ClearAddresses()
		{
			_addresses.Clear();
		}

		public void AddAddress(string addressName, string street, string city, string state, string zip)
		{
			AddAddress(new Address(addressName, street, city, state, zip));
		}

		public void AddAddress(Address address)
		{
			_addresses.Add(address);
		}

		#region ICloneable Members

		public object Clone()
		{
			Contact copy = (Contact) Activator.CreateInstance(GetType());
			copy._id = _id;
			copy._name = _name;
			_addresses.ForEach(delegate(Address a) { copy.AddAddress((Address) a.Clone()); });
			return copy;
		}

		#endregion
	}
}
